<?php

/**
 * Description of 
 *
 * @author Yefng
 */
namespace c\user;

class sv_phone extends \control
{
	//发送手机认证码
	function index_home()
	{
		$this->PU->login();
		$phone = \YF_f::$arr['login_user']['phone'];
		$b = $this->send($phone);
		if ($b)
			ajax_json($b);
        ajax_json(array('status'=>true, 'name'=>str_xx($phone, 6)));
	}
	/**
	 * 
	 * @param type $phone
	 * @param type $mark
	 * @return error
	 */
    function send($phone)
    {
        if (!$phone)
            return \lang::g ('not set phone');
		$mark = 'v-phone-'.$phone;
        $tempC = \YF_f::initC('\c\temp\db');
		//has
        $a = $tempC->findRow($mark);
        if ($a && UNIX_TIME - $a['create_time']<60)
            return 0;        
        //send
        $No = rand(1000,9999);
        $b = \YF_f::initC('\c\sms\g')->send($phone, sprintf(\lang::g('phone identifying code %s'), $No));
        if ($b)
           return $b;
        $tempC->save($mark, $No);
    }
	
	function che($phone, $ver)
	{
		$Ctem = \YF_f::initC('\c\temp\db');
		$mark = 'v-phone-' . $phone;
		$a = $Ctem->find_del($mark);
		if (!$a or UNIX_TIME - $a['create_time']>600)
			return \lang::g('Verification code has expired.');
		if ($a['val']!= $ver)
			return \lang::g('Verification code error.');
	}
}
